package com.leo.base_project.module.socket;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public abstract class BaseThread implements Runnable {

    protected final Socket mSocket;
    protected InputStream inputStream = null;
    protected OutputStream outputStream = null;
    protected BufferedInputStream bufferedInputStream = null;
    protected BufferedOutputStream bufferedOutputStream = null;
    protected BufferedReader mReader;

    public BaseThread(Socket mSocket) throws IOException {
        this.mSocket = mSocket;
        inputStream = mSocket.getInputStream();
        mReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
    }

    public void run() {
        try {
            handleSocket();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 跟客户端Socket进行通信
     *
     * @throws Exception
     */
    public abstract void handleSocket();
}